package soccer.view;
/// kalgıgın yer table  unvisible  yaptın sonra controller ekleme yapılacak 
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLayeredPane;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.MatteBorder;
import java.awt.Color;
import java.awt.ScrollPane;

import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;
import javax.swing.JComboBox;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.JSplitPane;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.JList;
import javax.swing.JButton;

public class PlayerSearchPanel extends JPanel {
	private JPanel searchByLicenceNoPanel;
	private JRadioButton searchLicenceRadioButton;
	private JRadioButton searchTeamRadioButton;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JRadioButton searchNameRadioButton;
	private JTextField searchedPlayerNameTextField;
	private JLabel searchedPlayerName;
	private JLabel searchedLicenceNoLabel;
	private JTextField searchedLicenceNoTextField;
	private JTable playersTable;
	private JComboBox teamsComboBox;
	private JLabel teamSelectComboboxLabel;
	private JButton searchPlayerButton;
	private JPanel searchByNamePanel1;
	private JPanel searchByLicenceNoPanel1;
	private JPanel searchByTeamPanel1;
	private JTextField searchedPlayerSurnameTextField1;
	private JScrollPane playerTablesSrollPane;
	private JLabel searchPlayerResultInfoLabel;
	private JButton backUserOptionButton;

	
	 /* Create the panel.
	 */
	public PlayerSearchPanel() {
      setLayout(null);
      
      searchNameRadioButton = new JRadioButton("By Name");
      buttonGroup.add(searchNameRadioButton);
      searchNameRadioButton.setBounds(135, 62, 109, 23);
      searchNameRadioButton.setSelected(true);
      searchNameRadioButton.setActionCommand("byName");
      add(searchNameRadioButton);
      
      searchLicenceRadioButton = new JRadioButton("By Licence No");
      buttonGroup.add(searchLicenceRadioButton);
      searchLicenceRadioButton.setBounds(264, 62, 109, 23);
      searchLicenceRadioButton.setActionCommand("byLicenceNo");
      add(searchLicenceRadioButton);
      
      searchTeamRadioButton = new JRadioButton("By Team");
      buttonGroup.add(searchTeamRadioButton);
      searchTeamRadioButton.setBounds(388, 62, 109, 23);
      searchTeamRadioButton.setActionCommand("byTeam");
      add(searchTeamRadioButton);
      
      playerTablesSrollPane = new JScrollPane();
      playerTablesSrollPane.setBounds(10, 182, 680, 98);
      playerTablesSrollPane.setVisible(false);
      add(playerTablesSrollPane);
      
      playersTable = new JTable();
      playerTablesSrollPane.setViewportView(playersTable);
      playersTable.setModel(new DefaultTableModel(
      	new Object[][] {
      		{null, null, null, null, null, null, null, null},
      	},
      	new String[] {
      		"Licence No", " Name", " Surname", "Place of birth", "Place of date", "Team", "Licence Star tDate", "Licence Finish Date"
      	}
      ));
      playersTable.getColumnModel().getColumn(0).setPreferredWidth(63);
      playersTable.getColumnModel().getColumn(1).setPreferredWidth(74);
      playersTable.getColumnModel().getColumn(2).setPreferredWidth(93);
      
     
      searchPlayerButton = new JButton("Search Player");
      searchPlayerButton.setBounds(135, 291, 122, 23);
      add(searchPlayerButton);
      
      searchedPlayerName = new JLabel("Player Name");
      searchedPlayerName.setBounds(10, 14, 91, 14);
      
       
       searchedPlayerNameTextField = new JTextField();
       searchedPlayerNameTextField.setBounds(145, 11, 116, 20);
       searchedPlayerNameTextField.setColumns(10);
       
       JLabel searchedPlayerSurname = new JLabel("Player Surname");
       searchedPlayerSurname.setBounds(10, 42, 75, 14);
       
       searchByNamePanel1 = new JPanel();
       searchByNamePanel1.setBounds(145, 92, 311, 67);
       add(searchByNamePanel1);
       searchByNamePanel1.setLayout(null);
       searchByNamePanel1.add(searchedPlayerSurname);
       searchByNamePanel1.add(searchedPlayerName);
       searchByNamePanel1.add(searchedPlayerNameTextField);
       
       searchedPlayerSurnameTextField1 = new JTextField();
       searchedPlayerSurnameTextField1.setBounds(145, 39, 116, 20);
       searchByNamePanel1.add(searchedPlayerSurnameTextField1);
       searchedPlayerSurnameTextField1.setColumns(10);
      
      searchByTeamPanel1 = new JPanel();
      searchByTeamPanel1.setBounds(145, 92, 311, 67);
      add(searchByTeamPanel1);
      searchByTeamPanel1.setLayout(null);
      searchByTeamPanel1.setVisible(false);
      
      teamSelectComboboxLabel = new JLabel("Team Select :");
      teamSelectComboboxLabel.setBounds(66, 25, 87, 14);
      searchByTeamPanel1.add(teamSelectComboboxLabel);
      
      teamsComboBox = new JComboBox();
      teamsComboBox.setBounds(163, 22, 101, 20);
      searchByTeamPanel1.add(teamsComboBox);
      
       
       searchByLicenceNoPanel1 = new JPanel();
       searchByLicenceNoPanel1.setBounds(145, 92, 311, 67);
       add(searchByLicenceNoPanel1);
       searchByLicenceNoPanel1.setLayout(null);
       searchByLicenceNoPanel1.setVisible(false);
       
       searchedLicenceNoLabel = new JLabel("Player Licence No :");
       searchedLicenceNoLabel.setBounds(10, 26, 108, 14);
       searchByLicenceNoPanel1.add(searchedLicenceNoLabel);
       
       searchedLicenceNoTextField = new JTextField();
       searchedLicenceNoTextField.setBounds(121, 23, 108, 20);
       searchByLicenceNoPanel1.add(searchedLicenceNoTextField);
       searchedLicenceNoTextField.setColumns(10);
       
       searchPlayerResultInfoLabel = new JLabel();
       searchPlayerResultInfoLabel.setForeground(new Color(153, 51, 0));
       searchPlayerResultInfoLabel.setBounds(145, 183, 321, 48);
       add(searchPlayerResultInfoLabel);
       
       backUserOptionButton = new JButton("Back to System");
       backUserOptionButton.setBounds(283, 291, 109, 23);
       add(backUserOptionButton);
      
	}
	
	public void addPlayersToPlayerTable(List playerList){
		if(playerList == null || playerList.size() < 1){
			
			searchPlayerResultInfoLabel.setText(" *The seaarched player is not found ");
			playerTablesSrollPane.setVisible(false);
			searchPlayerResultInfoLabel.setVisible(true);
			return;
		 }
		DefaultTableModel tableModel = (DefaultTableModel) playersTable.getModel();
        resetTeamTable(tableModel);
		for(int i = 0; i < playerList.size(); i++){
			Vector<Comparable> v = new Vector<Comparable>();
			Map player = (Map) playerList.get(i);
			v.add((Comparable) player.get("licenceNo"));
			v.add((Comparable) player.get("name"));
			v.add((Comparable) player.get("surname"));
			v.add((Comparable) player.get("birthPlace"));
			v.add((Comparable) player.get("birthDate"));
			v.add((Comparable) player.get("teamName"));
			v.add((Comparable) player.get("beginDateToLicence"));
			v.add((Comparable) player.get("finishDateToLicence"));
			tableModel.addRow(v);
		}
	 searchPlayerResultInfoLabel.setVisible(false);
     playerTablesSrollPane.setVisible(true);
	}
	public void selectBackToUserMenu(ActionListener l){
		backUserOptionButton.addActionListener(l);
	}
	public void resetTeamTable(DefaultTableModel model){
		while(model.getRowCount() > 0){
			model.removeRow(0);
		}
	}
	public void fillComboBoxWithTeams(List<Map> teamsName){
	    Object[] items = new Object[teamsName.size()];
	     
	    for(int i = 0; i < items.length; i++){
	    	Map item = teamsName.get(i);
	    	items[i] = item.get("teamName");
	    }
	    DefaultComboBoxModel model = new DefaultComboBoxModel(items);
		teamsComboBox.setModel(model);
    }
	public  Object getSelectedTeamFromComboBox(){
		Object selectedItem = teamsComboBox.getSelectedItem();
		return selectedItem;
	}
	public void setVisibleSearchNamePanel(){
		searchByNamePanel1.setVisible(true);
		searchByTeamPanel1.setVisible(false);
		searchByLicenceNoPanel1.setVisible(false);
	}
	public void setVisibleSearchLicencePanel(){
		searchByNamePanel1.setVisible(false);
		searchByTeamPanel1.setVisible(false);
		searchByLicenceNoPanel1.setVisible(true);
	}
	public void setVisibleSearchTeamPanel(){
		searchByNamePanel1.setVisible(false);
		searchByTeamPanel1.setVisible(true);
		searchByLicenceNoPanel1.setVisible(false);
	}
    public void addSearchLicenceRadioButtonActionListener(ActionListener l){
    	searchLicenceRadioButton.addActionListener(l);
    }
    public void addSearchNameRadioButtonActionListener(ActionListener l){
    	searchNameRadioButton.addActionListener(l);
    }
    public void addSearchTeamRadioButton(ActionListener l){
    	searchTeamRadioButton.addActionListener(l);
    }
    public void addSearchPlayerButtonActionListener(ActionListener l){
    	searchPlayerButton.addActionListener(l);
    }
    

	public JPanel getSearchByLicenceNoPanel() {
		return searchByLicenceNoPanel;
	}


	public void setSearchByLicenceNoPanel(JPanel searchByLicenceNoPanel) {
		this.searchByLicenceNoPanel = searchByLicenceNoPanel;
	}

	public JRadioButton getSearchLicenceRadioButton() {
		return searchLicenceRadioButton;
	}


	public void setSearchLicenceRadioButton(JRadioButton searchLicenceRadioButton) {
		this.searchLicenceRadioButton = searchLicenceRadioButton;
	}


	public JRadioButton getSearchTeamRadioButton() {
		return searchTeamRadioButton;
	}


	public void setSearchTeamRadioButton(JRadioButton searchTeamRadioButton) {
		this.searchTeamRadioButton = searchTeamRadioButton;
	}


	public JRadioButton getSearchNameRadioButton() {
		return searchNameRadioButton;
	}


	public JButton getBackUserOptionButton() {
		return backUserOptionButton;
	}

	public void setBackUserOptionButton(JButton backUserOptionButton) {
		this.backUserOptionButton = backUserOptionButton;
	}

	public void setSearchNameRadioButton(JRadioButton searchNameRadioButton) {
		this.searchNameRadioButton = searchNameRadioButton;
	}


	public JTextField getSearchedPlayerNameTextField() {
		return searchedPlayerNameTextField;
	}


	public void setSearchedPlayerNameTextField(
			JTextField searchedPlayerNameTextField) {
		this.searchedPlayerNameTextField = searchedPlayerNameTextField;
	}


	public JTextField getSearchedPalyerSurnameTextField() {
		return searchedPlayerNameTextField;
	}


	public void setSearchedPalyerSurnameTextField(
			JTextField searchedPalyerSurnameTextField) {
		this.searchedPlayerNameTextField = searchedPalyerSurnameTextField;
	}


	public JLabel getSearchedPlayerName() {
		return searchedPlayerName;
	}


	public void setSearchedPlayerName(JLabel searchedPlayerName) {
		this.searchedPlayerName = searchedPlayerName;
	}


	public JLabel getSearchedLicenceNoLabel() {
		return searchedLicenceNoLabel;
	}


	public void setSearchedLicenceNoLabel(JLabel searchedLicenceNoLabel) {
		this.searchedLicenceNoLabel = searchedLicenceNoLabel;
	}


	public JTextField getSearchedLicenceNoTextField() {
		return searchedLicenceNoTextField;
	}


	public void setSearchedLicenceNoTextField(JTextField searchedLicenceNoTextField) {
		this.searchedLicenceNoTextField = searchedLicenceNoTextField;
	}


	public JTable getTable() {
		return playersTable;
	}


	public void setTable(JTable table) {
		this.playersTable = table;
	}


	public JComboBox getTeamsComboBox() {
		return teamsComboBox;
	}


	public void setTeamsComboBox(JComboBox teamsComboBox) {
		this.teamsComboBox = teamsComboBox;
	}


	public JLabel getTeamSelectComboboxLabel() {
		return teamSelectComboboxLabel;
	}


	public void setTeamSelectComboboxLabel(JLabel teamSelectComboboxLabel) {
		this.teamSelectComboboxLabel = teamSelectComboboxLabel;
	}


	public ButtonGroup getButtonGroup() {
		return buttonGroup;
	}
	public JButton getSearchPlayerButton() {
		return searchPlayerButton;
	}
	public void setSearchPlayerButton(JButton searchPlayerButton) {
		this.searchPlayerButton = searchPlayerButton;
	}
	public JPanel getSearchByNamePanel_1() {
		return searchByNamePanel1;
	}
	public void setSearchByNamePanel_1(JPanel searchByNamePanel_1) {
		this.searchByNamePanel1 = searchByNamePanel_1;
	}
	public JPanel getSearchByLicenceNoPanel_1() {
		return searchByLicenceNoPanel1;
	}
	public void setSearchByLicenceNoPanel_1(JPanel searchByLicenceNoPanel_1) {
		this.searchByLicenceNoPanel1 = searchByLicenceNoPanel_1;
	}
	public JPanel getSearchByTeamPanel_1() {
		return searchByTeamPanel1;
	}
	public void setSearchByTeamPanel_1(JPanel searchByTeamPanel_1) {
		this.searchByTeamPanel1 = searchByTeamPanel_1;
	}
	public JTextField getSearchedPlayerSurnameTextField_1() {
		return searchedPlayerSurnameTextField1;
	}
	public void setSearchedPlayerSurnameTextField_1(
			JTextField searchedPlayerSurnameTextField_1) {
		this.searchedPlayerSurnameTextField1 = searchedPlayerSurnameTextField_1;
	}
}
